function sumColumn(convertFunction,name)
{
	name += '_';
	var inputs = document.getElementsByTagName("input");
	var result = 0;	
	var elemID = '';
	
	var i = 0;
	var value = 0;
	while(i < inputs.length)
	{
		elemID = inputs[i].id;		
		if(elemID.indexOf(name)==0){
			if((inputs[i].value != null) && (inputs[i].value != ''))
			{
				value = parseFloat(inputs[i].value.replace('.',','));	
				result = result + value;
			}
		}
		i++;
	}
	var evalVar = convertFunction + '(result)';
	return eval(evalVar);
}

function setPercent(nameColumn,dataColumn,totalColumn)
{
	name += '_';
	var inputs = document.getElementsByTagName("input");
	var result = 0;
	var elemID = '';
	
	var i = 0;
	while(i < inputs.length)
	{
		elemID = inputs[i].id;
		if(elemID.indexOf(dataColumn)==0){
			var index = 0;
			var mySplitResult = elemID.split("_");
			index = mySplitResult[4];			
			if(totalColumn > 0)
			{
				result =  inputs[i].value / totalColumn;
			}
			var evalVar = 'eedisplayPercentND(result,2)';
			var nameColumnIndex = nameColumn + "_" + index;
			document.getElementById(nameColumnIndex).value = eval(evalVar);
		}
		i++;
	}
}

function setCostaux(nameColumn,dataColumn,totalColumn)
{
	name += '_';
	var inputs = document.getElementsByTagName("input");
	var result = 0;
	var elemID = '';
	
	var i = 0;
	while(i < inputs.length)
	{
		elemID = inputs[i].id;
		if(elemID.indexOf(dataColumn)==0){
			var index = 0;
			var mySplitResult = elemID.split("_");
			index = mySplitResult[4];			
			if(totalColumn > 0)
			{
				result =  parseFloat(inputs[i].value.replace(',','.')) * totalColumn;				
			}
			var evalVar = 'eedisplayFloatND(result,0)';
			var nameColumnIndex = nameColumn + "_" + index;
			document.getElementById(nameColumnIndex).value = eval(evalVar);
		}
		i++;
	}
}

function setOperation(dataColumn1,dataColumn2,resultColumn,operation)
{
	name += '_';
	var inputs = document.getElementsByTagName("input");
	var elemID = '';
	
	var i = 0;
	while(i < inputs.length)
	{
		elemID = inputs[i].id;
		if(elemID.indexOf(dataColumn1)==0){
			var index = 0;
			var mySplitResult = elemID.split("_");
			index = mySplitResult[4];				
			var dcResult =  parseFloat(inputs[i].value);
			if(isNaN(dcResult))
			{
				dcResult = 0;
			}				
			
			var dataColumn2Index = dataColumn2 + "_" + index;
			var dcResult2 = parseFloat(document.getElementById(dataColumn2Index).value);
			
			if(isNaN(dcResult2))
			{
				dcResult2 = 0;
			}			
			
			var evalVar = 'dcResult' + operation +  'dcResult2';
			var resultColumnIndex = resultColumn + "_" + index;
			document.getElementById(resultColumnIndex).value = eedisplayFloatND(eval(evalVar),0);
		}
		i++;
	}
}

function calc(data) {
	
	var c1C3 = data.XLEW_1_3_3, c1F3 = data.XLEW_1_3_6;
	var c2C3 = c1C3, c3C3 = c1C3, c4C3 = c1C3, c5C3 = c1C3, 
	c2F3 = c1F3, c3F3 = c1F3, c4F3 = c1F3, c5F3 = c1F3;
	
	var c1E9, c1F9, c1G9, c1H9, c1I9, c1J9, c1K9, c1L9, c1M9, c1N9, c1O9;
	var c1E13, c1F13, c1G13, c1H13, c1I13, c1J13, c1K13, c1L13, c1M13, c1N13, c1O13;
	var c1E16, c1F16, c1G16, c1H16, c1I16, c1J16, c1K16, c1L16, c1M16, c1N16, c1O16;
	
	var c2E9, c2F9, c2G9, c2H9, c2I9, c2J9, c2K9, c2L9, c2M9, c2N9, c2O9;
	var c2E13, c2F13, c2G13, c2H13, c2I13, c2J13, c2K13, c2L13, c2M13, c2N13, c2O13;
	var c2E16, c2F16, c2G16, c2H16, c2I16, c2J16, c2K16, c2L16, c2M16, c2N16, c2O16;
	
	var c3E9, c3F9, c3G9, c3H9, c3I9, c3J9, c3K9, c3L9, c3M9, c3N9, c3O9;
	var c3E13, c3F13, c3G13, c3H13, c3I13, c3J13, c3K13, c3L13, c3M13, c3N13, c3O13;
	var c3E16, c3F16, c3G16, c3H16, c3I16, c3J16, c3K16, c3L16, c3M16, c3N16, c3O16;
	
	var c4E9, c4F9, c4G9, c4H9, c4I9, c4J9, c4K9, c4L9, c4M9, c4N9, c4O9;
	var c4E13, c4F13, c4G13, c4H13, c4I13, c4J13, c4K13, c4L13, c4M13, c4N13, c4O13;
	var c4E16, c4F16, c4G16, c4H16, c4I16, c4J16, c4K16, c4L16, c4M16, c4N16, c4O16;
	

	c1E9 = sumColumn('eeparseFloatTh','XLEW_1_8_5');
	c1E13 = sumColumn('eeparseFloatTh','XLEW_1_12_5');
	c1E16 = c1E9 + c1E13;
	if(c1E9 > 0)
	{
		c1F9 = 1;
	}
	else
	{
		c1F9 = 0;
	}
	
	setPercent('XLEW_1_8_6','XLEW_1_8_5',c1E9);
	setPercent('XLEW_1_12_6','XLEW_1_12_5',c1E13);
	if(c1E13 > 0)
	{
		c1F13 = 1;
	}
	else
	{
		c1F13 = 0;
	}
	
	c1G9 = sumColumn('eeparseFloatTh','XLEW_1_8_7');
	setCostaux('XLEW_1_8_8', 'XLEW_1_8_6', c1E13);
	c1H9 = sumColumn('eeparseFloatTh','XLEW_1_8_8');
	setOperation('XLEW_1_8_7', 'XLEW_1_8_8','XLEW_1_8_9','+');
	c1I9 = sumColumn('eeparseFloatTh','XLEW_1_8_9');
	c1J9 = sumColumn('eeparseFloatTh','XLEW_1_8_10');
	c1K9 = sumColumn('eeparseFloatTh','XLEW_1_8_11');
	c1L9 = sumColumn('eeparseFloatTh','XLEW_1_8_12');
	c1M9 = parseFloat(c1G9.toString().replace('.','')) / parseFloat(c1E9.toString().replace('.',''));
	c1N9 = parseFloat(c1I9.toString().replace('.','')) / parseFloat(c1E9.toString().replace('.',''));
	
	c1G13 = sumColumn('eeparseFloatTh','XLEW_1_12_7');
	c1H13 = sumColumn('eeparseFloatTh','XLEW_1_12_8');
	c1I13 = sumColumn('eeparseFloatTh','XLEW_1_12_9');
	c1J13 = sumColumn('eeparseFloatTh','XLEW_1_12_10');
	c1K13 = sumColumn('eeparseFloatTh','XLEW_1_12_11');
	c1L13 = sumColumn('eeparseFloatTh','XLEW_1_12_12');
			
	c2H9 = sumColumn('eeparseFloatTh','XLEW_2_8_8');
	c2I9 = sumColumn('eeparseFloatTh','XLEW_2_8_9');
	c2J9 = sumColumn('eeparseFloatTh','XLEW_2_8_10');
	c2K9 = sumColumn('eeparseFloatTh','XLEW_2_8_11');	
	c2H13 = sumColumn('eeparseFloatTh','XLEW_2_12_8');
	c2I13 = sumColumn('eeparseFloatTh','XLEW_2_12_9');
	c2J13 = sumColumn('eeparseFloatTh','XLEW_2_12_10');
	c2K13 = sumColumn('eeparseFloatTh','XLEW_2_12_11');	
	
	c3E9 = sumColumn('eeparseFloatTh','XLEW_3_8_5');
	c3F9 = sumColumn('eeparseFloatTh','XLEW_3_8_6');
	c3G9 = sumColumn('eeparseFloatTh','XLEW_3_8_7');
	c3H9 = sumColumn('eeparseFloatTh','XLEW_3_8_8');
	c3I9 = sumColumn('eeparseFloatTh','XLEW_3_8_9');
	c3J9 = sumColumn('eeparseFloatTh','XLEW_3_8_10');
	c3K9 = sumColumn('eeparseFloatTh','XLEW_3_8_11');
	c3L9 = sumColumn('eeparseFloatTh','XLEW_3_8_12');
	c3M9 = sumColumn('eeparseFloatTh','XLEW_3_8_13');
	c3N9 = 0;
	c3O9 = 0;
	
	c3E13 = sumColumn('eeparseFloatTh','XLEW_3_12_5');
	c3F13 = sumColumn('eeparseFloatTh','XLEW_3_12_6');
	c3G13 = sumColumn('eeparseFloatTh','XLEW_3_12_7');
	c3H13 = sumColumn('eeparseFloatTh','XLEW_3_12_8');
	c3I13 = sumColumn('eeparseFloatTh','XLEW_3_12_9');
	c3J13 = sumColumn('eeparseFloatTh','XLEW_3_12_10');
	c3K13 = sumColumn('eeparseFloatTh','XLEW_3_12_11');
	c3L13 = sumColumn('eeparseFloatTh','XLEW_3_12_12');
	c3M13 = sumColumn('eeparseFloatTh','XLEW_3_12_13');
	c3N13 = 0;
	c3O13 = 0;
	
		
	c4E9 = sumColumn('eeparseFloatTh','XLEW_4_8_5');
	c4F9 = sumColumn('eeparseFloatTh','XLEW_4_8_6');
	c4G9 = sumColumn('eeparseFloatTh','XLEW_4_8_7');
	c4H9 = sumColumn('eeparseFloatTh','XLEW_4_8_8');
	c4I9 = sumColumn('eeparseFloatTh','XLEW_4_8_9');
	c4J9 = sumColumn('eeparseFloatTh','XLEW_4_8_10');
	c4K9 = sumColumn('eeparseFloatTh','XLEW_4_8_11');
	c4L9 = sumColumn('eeparseFloatTh','XLEW_4_8_12');
	c4M9 = sumColumn('eeparseFloatTh','XLEW_4_8_13');
	c4N9 = sumColumn('eeparseFloatTh','XLEW_4_8_14');
	c4O9 = sumColumn('eeparseFloatTh','XLEW_4_8_15');
	
	c4E13 = sumColumn('eeparseFloatTh','XLEW_4_12_5');
	c4F13 = sumColumn('eeparseFloatTh','XLEW_4_12_6');
	c4G13 = sumColumn('eeparseFloatTh','XLEW_4_12_7');
	c4H13 = sumColumn('eeparseFloatTh','XLEW_4_12_8');
	c4I13 = sumColumn('eeparseFloatTh','XLEW_4_12_9');
	c4J13 = sumColumn('eeparseFloatTh','XLEW_4_12_10');
	c4K13 = sumColumn('eeparseFloatTh','XLEW_4_12_11');
	c4L13 = sumColumn('eeparseFloatTh','XLEW_4_12_12');
	c4M13 = sumColumn('eeparseFloatTh','XLEW_4_12_13');
	c4N13 = sumColumn('eeparseFloatTh','XLEW_4_12_14');
	c4O13 = sumColumn('eeparseFloatTh','XLEW_4_12_15');
	
	
//	c1E16 = c1E9 + c1E13;
	c1F16 = c1F9 + c1F13;
	c1G16 = c1G9 + c1G13;
	c1H16 = c1H9 + c1H13;
	c1I16 = c1I9 + c1I13;
	c1J16 = c1J9 + c1J13;
	c1K16 = c1K9 + c1K13;
	c1L16 = c1L9 + c1L13;
	
	c2H16 = c2H9 + c2H13;
	c2I16 = c2I9 + c2I13;
	c2J16 = c2J9 + c2J13;
	c2K16 = c2K9 + c2K13;
			
	data.XLEW_5_3_3 = c5C3;
	data.XLEW_5_3_6 = c5F3;
	
	data.XLEW_4_3_3 = c4C3;
	data.XLEW_4_3_6 = c4F3;
	
	data.XLEW_4_9_5 = c4E9;
	data.XLEW_4_9_6 = c4F9;
	data.XLEW_4_9_7 = c4G9;
	data.XLEW_4_9_8 = c4H9;
	data.XLEW_4_9_9 = c4I9;
	data.XLEW_4_9_10 = c4J9;
	data.XLEW_4_9_11 = c4K9;
	data.XLEW_4_9_12 = c4L9;
	data.XLEW_4_9_13 = c4M9;
	data.XLEW_4_9_14 = c4N9;
	data.XLEW_4_9_15 = c4O9;
	
	data.XLEW_4_13_5 = c4E13;
	data.XLEW_4_13_6 = c4F13;
	data.XLEW_4_13_7 = c4G13;
	data.XLEW_4_13_8 = c4H13;
	data.XLEW_4_13_9 = c4I13;
	data.XLEW_4_13_10 = c4J13;
	data.XLEW_4_13_11 = c4K13;
	data.XLEW_4_13_12 = c4L13;
	data.XLEW_4_13_13 = c4M13;
	data.XLEW_4_13_14 = c4N13;
	data.XLEW_4_13_15 = c4O13;
		
	data.XLEW_3_3_3 = c3C3;
	data.XLEW_3_3_6 = c3F3;
	
	data.XLEW_3_9_5 = c3E9;
	data.XLEW_3_9_6 = c3F9;
	data.XLEW_3_9_7 = c3G9;
	data.XLEW_3_9_8 = c3H9;
	data.XLEW_3_9_9 = c3I9;
	data.XLEW_3_9_10 = c3J9;
	data.XLEW_3_9_11 = c3K9;
	data.XLEW_3_9_12 = c3L9;
	data.XLEW_3_9_13 = c3M9;
	data.XLEW_3_9_14 = c3N9;
	data.XLEW_3_9_15 = c3O9;

	data.XLEW_3_13_5 = c3E13;
	data.XLEW_3_13_6 = c3F13;
	data.XLEW_3_13_7 = c3G13;
	data.XLEW_3_13_8 = c3H13;
	data.XLEW_3_13_9 = c3I13;
	data.XLEW_3_13_10 = c3J13;
	data.XLEW_3_13_11 = c3K13;
	data.XLEW_3_13_12 = c3L13;
	data.XLEW_3_13_13 = c3M13;
	data.XLEW_3_13_14 = c3N13;
	data.XLEW_3_13_15 = c3O13;
	
		
	data.XLEW_2_3_3 = c2C3;
	data.XLEW_2_3_6 = c2F3;
	
	data.XLEW_2_9_5 = c2E9;
	data.XLEW_2_9_6 = c2F9;
	data.XLEW_2_9_7 = c2G9;
	data.XLEW_2_9_8 = c2H9;
	data.XLEW_2_9_9 = c2I9;
	data.XLEW_2_9_10 = c2J9;
	data.XLEW_2_9_11 = c2K9;
	data.XLEW_2_9_12 = c2L9;
	data.XLEW_2_9_13 = c2M9;
	data.XLEW_2_9_14 = c2N9;
	data.XLEW_2_9_15 = c2O9;
	
	data.XLEW_2_13_5 = c2E13;
	data.XLEW_2_13_6 = c2F13;
	data.XLEW_2_13_7 = c2G13;
	data.XLEW_2_13_8 = c2H13;
	data.XLEW_2_13_9 = c2I13;
	data.XLEW_2_13_10 = c2J13;
	data.XLEW_2_13_11 = c2K13;
	data.XLEW_2_13_12 = c2L13;
	data.XLEW_2_13_13 = c2M13;
	data.XLEW_2_13_14 = c2N13;
	data.XLEW_2_13_15 = c2O13;
	
	data.XLEW_2_16_5 = c2E16;
	data.XLEW_2_16_6 = c2F16;
	data.XLEW_2_16_7 = c2G16;
	data.XLEW_2_16_8 = c2H16;
	data.XLEW_2_16_9 = c2I16;
	data.XLEW_2_16_10 = c2J16;
	data.XLEW_2_16_11 = c2K16;
	data.XLEW_2_16_12 = c2L16;
	data.XLEW_2_16_13 = c2M16;
	data.XLEW_2_16_14 = c2N16;
	data.XLEW_2_16_15 = c2O16;
		
	data.XLEW_1_9_5 = c1E9;
	data.XLEW_1_9_6 = c1F9;
	data.XLEW_1_9_7 = c1G9;
	data.XLEW_1_9_8 = c1H9;
	data.XLEW_1_9_9 = c1I9;
	data.XLEW_1_9_10 = c1J9;
	data.XLEW_1_9_11 = c1K9;
	data.XLEW_1_9_12 = c1L9;
	data.XLEW_1_9_13 = c1M9;
	data.XLEW_1_9_14 = c1N9;
	data.XLEW_1_9_15 = c1O9;
	
	data.XLEW_1_13_5 = c1E13;
	data.XLEW_1_13_6 = c1F13;
	data.XLEW_1_13_7 = c1G13;
	data.XLEW_1_13_8 = c1H13;
	data.XLEW_1_13_9 = c1I13;
	data.XLEW_1_13_10 = c1J13;
	data.XLEW_1_13_11 = c1K13;
	data.XLEW_1_13_12 = c1L13;
	data.XLEW_1_13_13 = c1M13;
	data.XLEW_1_13_14 = c1N13;
	data.XLEW_1_13_15 = c1O13;
	
	data.XLEW_1_16_5 = c1E16;
	data.XLEW_1_16_6 = c1F16;
	data.XLEW_1_16_7 = c1G16;
	data.XLEW_1_16_8 = c1H16;
	data.XLEW_1_16_9 = c1I16;
	data.XLEW_1_16_10 = c1J16;
	data.XLEW_1_16_11 = c1K16;
	data.XLEW_1_16_12 = c1L16;
	data.XLEW_1_16_13 = c1M16;
	data.XLEW_1_16_14 = c1N16;
	data.XLEW_1_16_15 = c1O16;
	
	
}